<template>
  <el-dialog v-if="isOpen" title="决议审批" :visible.sync="isOpen" width="600px" append-to-body>
    <el-form ref="form" :model="auditForm" :rules="rules" label-width="140px">
      <el-form-item label="审批结论" prop="audit_type">
        <el-radio-group v-model="auditForm.audit_type" @change="auditTypeChange">
          <el-radio label="Next">立项决议结论</el-radio>
          <el-radio label="Refuse">重新调研-[未通过]</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="auditForm.audit_type==='Next'" label="选择立项决议结论" prop="check_status">
        <el-select
          v-model="auditForm.check_status"
          placeholder="请选择立项决议结论"
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in auditOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审批意见" prop="remark">
        <el-input
          v-model="auditForm.remark"
          type="textarea"
          placeholder="请输入审批意见"
          :autosize="{ minRows: 3, maxRows: 6 }"
          :style="{ width: '100%' }"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { resolutionEvaluate } from '@/api/projectInformation'
export default {
  props: {
    projectId: {
      type: String,
      default: () => {}
    },
    auditData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      isOpen: false,
      user_id: '',
      auditForm: {
        audit_type: 'Next',
        check_status: 1,
        remark: ''
      },
      bottons: [],
      auditOptions: [
        {
          label: '同意立项',
          value: 1
        },
        {
          label: '不予立项',
          value: 2
        },
        {
          label: '暂时搁置',
          value: 3
        }
      ],
      // 弹框
      rules: {
        audit_type: [
          { required: true, message: '请选择审批结论', trigger: 'blur' }
        ],
        check_status: [
          { required: true, message: '请选择评估结论', trigger: 'blur' }
        ],
        remark: []
      }
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  methods: {
    // 表单重置
    reset() {
      this.auditForm = {
        audit_type: 'Next',
        check_status: 1,
        remark: ''
      }
      this.resetForm('form')
    },
    // 取消按钮
    close() {
      this.isOpen = false
      this.reset()
    },
    // 打开弹框
    open() {
      this.isOpen = true
    },
    /** 提交按钮 */
    submitForm() {
      const that = this
      this.$refs['form'].validate((valid) => {
        if (valid) {
          that.resolutionEvaluateOperation()
        }
      })
    },
    auditTypeChange(val) {
      console.log(val)
      if (val === 'Refuse') {
        this.auditForm.check_status = 4
      } else if (val === 'Next') {
        this.auditForm.check_status = 1
      }
      this.auditForm.remark = ''
    },
    resolutionEvaluateOperation() {
      const subdata = {
        id: this.projectId,
        check_status: this.auditForm.audit_type,
        agree_status: this.auditForm.check_status,
        remark: this.auditForm.remark
      }
      resolutionEvaluate(subdata).then(res => {
        if (res.code === 200) {
          this.close()
          this.$emit('evaluationSuccess')
        } else {
          this.$message({
            type: 'error',
            message: res.msg
          })
        }
      })
    }
  }
}
</script>
<style scoped>
/* @import url(); 引入css类 */
</style>
